#include "test.h"
#include "misc_utils.h"

void test_packet_buffer(void)
{
    unsigned int i;
    unsigned int count = 100;

    PACKET_BUFFER_T pb;

    packet_buffer_init(&pb);
    for (i = 0; i < count; i++)
    {
        packet_buffer_push_uint8(&pb, (unsigned char)i);
        packet_buffer_push_uint16(&pb, (unsigned short)(i * 2));
        packet_buffer_push_uint32(&pb, (unsigned int)(i * 4));
    }

    for (i = 0; i < count; i++)
    {
        int rc;
        unsigned char u8;
        unsigned short u16;
        unsigned int u32;

        rc = packet_buffer_shift_uint8(&pb, &u8);
        EXPECT((rc == 1) && (u8 == i));

        rc = packet_buffer_shift_uint16(&pb, &u16);
        EXPECT((rc == 1) && (u16 == i*2));

        rc = packet_buffer_shift_uint32(&pb, &u32);
        EXPECT((rc == 1) && (u32 == i*4));
    }
    packet_buffer_destroy(&pb);
}
